//
//  UINavigationController+GKCategory.swift
//  LXPageScrollVeiw
//
//  Created by 赵连勋 on 2019/4/11.
//  Copyright © 2019 赵连勋. All rights reserved.
//

import UIKit

extension UINavigationController {
    ///只调用一次
    public class func initializeMethod(){
        lx_swizzled_method(cls: self, originalSelector: #selector(UINavigationController.viewDidLoad), swizzledSelector: #selector(UINavigationController.lx_viewDidLoad))
        // FIXME: 修复iOS11之后push或pop动画为NO，系统不主动调用UINavigationBar的layoutSubviews方法
        if Double(UIDevice.current.systemVersion)! >= 11.0 {
            lx_swizzled_method(cls: self, originalSelector: #selector(UINavigationController.pushViewController(_:animated:)), swizzledSelector: #selector(UINavigationController.lx_pushViewController(viewController:animated:)))
        }
        
    }
    class func rootVc(rootVc: UIViewController, translationScale: Bool) -> Self
    {
        let vc = self.init()
        vc.lx_translationScale = translationScale
        vc.pushViewController(rootVc, animated: true)
        return vc
    }
    
    ///导航栏转场时是否缩放,此属性只能在初始化导航栏的时候有效，在其他地方设置会导致错乱
    private(set) var lx_translationScale: Bool? {
        get {return false}
        set{}
    }
    /// 是否开启左滑push操作，默认是NO，此时不可禁用控制器的滑动返回手势
//    var lx_openScrollLeftPush: Bool? {
//
//    }
    
    @objc func lx_viewDidLoad() {
        //处理特殊控制器
        if self.isKind(of: UIImagePickerController.self) { return }
        if self.isKind(of: UIVideoEditorController.self) { return }
        //设置背景色
        view.backgroundColor = UIColor.black
        //FIXME:自定义navDelegate之后，在这里设置一下
        //设置代理
//        self.delegate = self.navDelegate
        //注册通知
        NotificationCenter.default.addObserver(self, selector: #selector(handleNotification(notify:)), name: NSNotification.Name(LXViewControllerPropertyChangedNotification), object: nil)
        
        lx_viewDidLoad()
    }
    @objc func lx_pushViewController(viewController: UIViewController, animated: Bool) {
        lx_pushViewController(viewController: viewController, animated: animated)
    }
    
    //- MARK:Notification Handle
    @objc func handleNotification(notify: Notification) {
//        let vc = notify.object as! [String: Any]
        let vc = notify.userInfo?["viewController"] as! UIViewController
        let isRootVc = (vc == self.viewControllers.first)
        // 重新根据属性添加手势方法
//        if vc. {
//            <#code#>
//        }
    }
}
